#! /usr/bin/make

LIBS = -lfl -lSDL
CXXFLAGS = -g -MMD -Wall -O1 -std=c++0x
ETAGS = /usr/bin/etags
VERSION ?= "DEBUG"
prefix = $(DESTDIR)/usr/local
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
localstatedir = $(prefix)/var

OBJ = data_structures.o gac_lang.o read_data.o write_data.o editor.o simple_reader.o p-machine.o adventure-loop.o # gac_lexer.o
BIN = advent2 #p-machine-tester #gac_lang #edit-picture

.PHONY: all
all:	bin

libadventure.a:	  $(OBJ)
	ar rcs $@ $^

.PHONY: bin
bin:	$(BIN)

install:
	install -d $(bindir)
	install -s -t $(bindir) $(BIN)

edit-picture: libadventure.a edit-picture.o
	g++ $(CXXFLAGS) -o $@ $^ $(LIBS)

advent2: advent2.o libadventure.a
	g++ $(CXXFLAGS) -o $@ $^ $(LIBS)

p-machine-tester: p-code-tester.o libadventure.a
	g++ $(CXXFLAGS) -o $@ $^ $(LIBS)

gac_lang:	gac_lang.tab.o libadventure.a
	g++ $(CXXFLAGS) -o $@ $^ $(LIBS)

gac_lexer.cc: gac_lexer.l gac_lang.tab.cc
	flex -o $@ $<

%.tab.cc:	%.yy
	bison	-d $^

.PHONY: clean
clean:
	rm -f *.o *.d *.tab.* $(BIN) libadventure.a TAGS gac_lexer.cc

.PHONY: distclean
distclean:	clean

.PHONY: tags
tags:
	$(ETAGS) *.cc *.hh

-include $(OBJ:.o=.d)
:
-include $(OBJ:.o=.d)

